package com.ee.chat.api.controller;

import com.ee.chat.api.service.IBaseService;
import com.ee.chat.api.vo.EquipmentVO;
import com.ee.chat.common.bean.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author Shane
 * @Date 2019/7/23 14:33
 */
@RestController
@RequestMapping("base")
public class BaseController {
    private Logger log = LoggerFactory.getLogger(BaseController.class);

    @Resource
    IBaseService baseService;

    /**
     * 发送验证码
     *
     * @param phone 手机号
     * @param op    操作，login-注册登录  bind-绑定或修改手机号
     * @return
     */
    @RequestMapping("sendCode")
    public Result sendCode(@RequestParam(required = false) String token, @RequestParam String phone, @RequestParam String op) {
        try {
            return baseService.sendCode(token, phone, op);
        } catch (Exception e) {
            log.error("【发送验证码错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取上传凭证
     *
     * @param
     * @return
     * @Author Shane
     * @Date 2019/7/23 15:08
     */
    @RequestMapping("getUploadToken")
    public Result getUploadToken(HttpServletRequest request, String fileName) {
        try {
            return baseService.getUploadToken(request, fileName);
        } catch (Exception e) {
            log.error("【获取上传凭证错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取上传签名
     *
     * @param
     * @return
     * @Author Shane
     * @Date 2019/9/1815:00
     **/
    @RequestMapping("getUploadSign")
    public Result getUploadSign(HttpServletRequest request) {
        try {
            return baseService.getUploadSign(request);
        } catch (Exception e) {
            log.error("【获取上传签名错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取基本信息
     *
     * @return
     * @Author Shane
     * @Date 2019/7/26 1:18
     */
    @RequestMapping("getBaseInfo")
    public Result getBaseInfo(@RequestParam(required = false) String token, @RequestParam String extra) {
        try {
            return baseService.getBaseInfo(token, extra);
        } catch (Exception e) {
            log.error("【获取基本信息错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 校验敏感词
     *
     * @param list 语句
     * @return
     * @Author Shane
     * @Date 2019/10/11 0:20
     */
    @RequestMapping("verifySensitiveWord")
    public Result verifySensitiveWord(String token, @RequestParam String list) {
        try {
            return baseService.verifySensitiveWord(token, list);
        } catch (Exception e) {
            log.error("【获取基本信息错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取最新版本信息
     *
     * @param type 类型，0-android  1-ios(tf)  2-ios(appstore)  3-ios(enter)
     * @return
     * @Author Shane
     * @Date 2019/11/26 16:47
     **/
    @RequestMapping("getNewestVersion")
    public Result getNewestVersion(@RequestParam Integer type) {
        try {
            return baseService.getNewestVersion(type);
        } catch (Exception e) {
            log.error("【获取最新版本信息错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 阿里云oss上传回调
     *
     * @param
     * @return
     * @Author Shane
     * @Date 2020/2/28 16:55
     */
    @RequestMapping("ossCallback")
    public Object ossCallback(HttpServletRequest request) throws Exception {
        try {
            return baseService.ossCallback(request);
        } catch (Exception e) {
            log.error("【阿里云oss上传回调错误】", e);
            throw new Exception(e);
        }
    }

    /**
     * 记录打开分享邀请链接的设备信息
     *
     * @param
     * @return
     * @Author Shane
     * @Date 2020/7/6 13:57
     */
    @RequestMapping("addClickLog")
    public Object addClickLog(HttpServletRequest request, EquipmentVO equipment) throws Exception {
        try {
            return baseService.addClickLog(request, equipment);
        } catch (Exception e) {
            log.error("【记录打开分享邀请链接的设备信息错误】", e);
            throw new Exception(e);
        }
    }

}
